package ${basepackage}.${projectName}.web.admin.controller;

import ${basepackage}.${projectName}.domain.${table.className}Bean;
import ${basepackage}.${projectName}.domain.security.User;
import ${basepackage}.${projectName}.service.${table.className}Service;
import ${basepackage}.${projectName}.web.admin.constant.Uri;
import ${basepackage}.${projectName}.web.admin.controller.common.BaseController;
import ${basepackage}.${projectName}.web.admin.utils.ExecuteResult;
import ${basepackage}.${projectName}.web.admin.vo.PageParams;
import cc.hwtech.core.mybatis.domain.Page;
import cc.hwtech.core.mybatis.domain.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>Project: bee-projects</p>
 * <p>Title: ${table.className}Controller.java</p>
 * <p>Description:   </p>
 * <p>Copyright: Copyright (c) 2016 </p>
 * <p>Company: 华炜云商科技有限公司 www.hwtech.cc</p>
 *
 * @author zh
 * @version 1.0
 * @date 2017-03-09
 */
@Controller
public class ${table.className}Controller extends BaseController {

    @Autowired
    private ${table.className}Service ${table.classNameFirstLower}Service;

    /**
     * 展示-分页
     * @param request           [必填] request对象
     * @param pageParams        [必填] 分页参数
     * @param ${table.classNameFirstLower}Bean       [必填] 搜索条件
     * @return
     */
    @RequestMapping(value = Uri.${table.sqlNameUpperCase}_PAGE_SHOW)
    public ModelAndView showPage(HttpServletRequest request, PageParams pageParams, ${table.className}Bean ${table.classNameFirstLower}Bean){
        ModelAndView modelAndView = new ModelAndView();
        User user = this.getUser(request);
        //构建pageRequest
        PageRequest pageRequest = this.handlePageParams(pageParams);
        //查找
        Page<${table.className}Bean> entityList = ${table.classNameFirstLower}Service.findBeanPage(pageRequest, ${table.classNameFirstLower}Bean, user.getaId());

        modelAndView.addObject("searchObj",${table.classNameFirstLower}Bean);
        modelAndView.setViewName("${table.sqlNameLowerCase}/show");
        this.handlePageData(entityList, pageParams, request);
        return  modelAndView;
    }

    /**
     * 展示-详情
     * @param request           [必填] request对象
     * @param id                [必填] ID
     * @return
     */
    @RequestMapping(value = Uri.${table.sqlNameUpperCase}_DETAIL_SHOW)
    public ModelAndView showDetail(HttpServletRequest request, ${table.idColumn.simpleJavaType} id) {
        ModelAndView modelAndView = new ModelAndView();
        ${table.className}Bean ${table.classNameFirstLower}Bean = ${table.classNameFirstLower}Service.findBeanById(id, null);
        modelAndView.addObject("entity", ${table.classNameFirstLower}Bean);
        modelAndView.setViewName("${table.sqlNameLowerCase}/detail");
        return  modelAndView;
    }

    /**
     * 新增-页面
     * @param request           [必填] request对象
     * @return
     */
    @RequestMapping(value = Uri.${table.sqlNameUpperCase}_ADD_SHOW)
    public ModelAndView showAdd(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("${table.sqlNameLowerCase}/add_update_show");
        return  modelAndView;
    }

    /**
     * 新增-提交
     * @param request           [必填] request对象
     * @param ${table.classNameFirstLower}Bean       [必填] 包含新增字段信息的bean
     * @return
     */
    @RequestMapping(value = Uri.${table.sqlNameUpperCase}_ADD_SUBMIT)
    @ResponseBody
    public Object doAddSubmit(HttpServletRequest request, ${table.className}Bean ${table.classNameFirstLower}Bean){
        ${table.classNameFirstLower}Service.doAdd(${table.classNameFirstLower}Bean, this.getUser(request));
        return ExecuteResult.jsonReturn(200, Uri.${table.sqlNameUpperCase}_PAGE_SHOW);
    }

    /**
     * 编辑-页面
     * @param request           [必填] request对象
     * @return
     */
    @RequestMapping(value = Uri.${table.sqlNameUpperCase}_UPDATE_SHOW)
    public ModelAndView showUpdate(HttpServletRequest request, ${table.idColumn.simpleJavaType} id) {
        ModelAndView modelAndView = new ModelAndView();
        User user = this.getUser(request);
        ${table.className}Bean ${table.classNameFirstLower}Bean = ${table.classNameFirstLower}Service.findBeanById(id, user.getaId());
        modelAndView.addObject("entity", ${table.classNameFirstLower}Bean);
        modelAndView.setViewName("${table.sqlNameLowerCase}/add_update_show");
        return  modelAndView;
    }

    /**
     * 编辑-提交
     * @param request           [必填] request对象
     * @param ${table.classNameFirstLower}Bean       [必填] 包含编辑信息的bean
     * @return
     */
    @RequestMapping(value = Uri.${table.sqlNameUpperCase}_UPDATE_SUBMIT)
    @ResponseBody
    public Object doUpdateSubmit(HttpServletRequest request, ${table.className}Bean ${table.classNameFirstLower}Bean){
        ${table.classNameFirstLower}Service.doUpdate(${table.classNameFirstLower}Bean, this.getUser(request));
        return ExecuteResult.jsonReturn(200, Uri.${table.sqlNameUpperCase}_PAGE_SHOW);
    }

    /**
     * 软删除-提交
     * @param request           [必填] request对象
     * @param id                [必填] ID
     * @return
     */
    @RequestMapping(value = Uri.${table.sqlNameUpperCase}_DEL_SUBMIT)
    @ResponseBody
    public Object doDelSubmit(HttpServletRequest request, ${table.idColumn.simpleJavaType} id){
        ${table.classNameFirstLower}Service.doDel(id, this.getUser(request));
        return ExecuteResult.jsonReturn(200, null);
    }

    /**
     * 删除-提交
     * @param request           [必填] request对象
     * @param id                [必填] ID
     * @return
     */
    @RequestMapping(value = Uri.${table.sqlNameUpperCase}_DELETE_SUBMIT)
    @ResponseBody
    public Object doDeleteSubmit(HttpServletRequest request, ${table.idColumn.simpleJavaType} id){
        ${table.classNameFirstLower}Service.doDelete(id, this.getUser(request));
        return ExecuteResult.jsonReturn(200, null);
    }
}